package com.hang.service.impl;

import com.alibaba.excel.EasyExcel;
import com.hang.common.BizErrorCodeEnum;
import com.hang.common.BizException;
import com.hang.mapper.ClazzMapper;
import com.hang.service.AdminService;
import com.hang.service.IMailService;
import com.hang.util.listener.ClazzListener;
import com.hang.util.listener.StudentListener;
import com.hang.vo.ClazzVo;
import com.hang.vo.FeedBackVo;
import com.hang.vo.StudentVo;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private ClazzMapper clazzMapper;

    @Autowired
    private IMailService iMailService;

    /**
     * 导入班级信息
     * @param multipartFile
     */
    @Override
    public void insertInformation(MultipartFile multipartFile) {
        try{
            EasyExcel.read(multipartFile.getInputStream(), ClazzVo.class,new ClazzListener(clazzMapper))
                    .sheet()
                    .doRead();
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    /**
     * 反馈信息
     * @param feedBackVo
     */
    @Override
    public Map<String,Object> feedBack(FeedBackVo feedBackVo) {
        if(ObjectUtils.isEmpty(feedBackVo)){
            throw new BizException(BizErrorCodeEnum.OBJECT_IS_NULL);
        }

        Map<String,Object> map = new HashMap<>();
        try {
            iMailService.sendSimpleMail(
                "1057545710@qq.com",
                feedBackVo.getTel()+"的反馈意见:"+feedBackVo.getTitle(),
                feedBackVo.getContent()
            );
            map.put("message","我们已经收到您的意见，稍后会联系您~");
        }catch (Exception e){
            map.put("message","反馈失败，请联系管理员:13690630078");
        }

        return map;
    }
}